package com.nmsl.statistic.controller;

import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.medicine.domain.Medicine;
import com.nmsl.medicine.mapper.MedicineMapper;
import com.nmsl.medicine.service.IMedicineService;
import com.nmsl.statistic.constants.Constants;
import com.nmsl.statistic.domain.RedisPage;
import com.nmsl.statistic.domain.RetailMedicine;
import com.nmsl.statistic.mapper.GetmedicInfoMapper;
import com.nmsl.statistic.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/jwkMedicine")
public class jwkMedicineController extends BaseController {

    @Autowired
    private GetmedicInfoMapper getmedicInfoMapper;

    @Autowired
    RedisTemplate redisTemplate;
    @RequestMapping("/list")
    public AjaxResult getjwkMedicine(@RequestBody Map<String,String> s){
        startPage();
        Medicine medicine = new Medicine();
        medicine.setPrescriptionName(s.get("type"));
        medicine.setMedicineName(s.get("Name"));
        List<Medicine> list = getmedicInfoMapper.selectMedicineList(medicine);
//        System.out.println(list.get(0));
        // 名字模糊查询查询
        System.out.println(list);
        return AjaxResult.success(list);
//        return getDataTable(list);
    }

    @RequestMapping("/ranking")
    public AjaxResult selecetByRetailOrderId(@RequestBody Map<String,Long> params)   {
        System.out.println(params.toString());
        Long curentPage =  params.get("curentPage");
        Long size = params.get("size");
        RedisPage medicinesRanking = RedisUtil.getMedicinesRanking(redisTemplate, curentPage, size, Constants.medicinesRetailRanking, Integer.class);
        System.out.println(medicinesRanking);
        Set<RetailMedicine> retailMedicines = getmedicInfoMapper.selectByIDs(medicinesRanking.getData());
        System.out.println(retailMedicines);
        return AjaxResult.success(retailMedicines);
    }
}
